package com.example.wxminiprogram.service.GoodsServiceImpl;

import com.example.wxminiprogram.mapper.SellerMapper;
import com.example.wxminiprogram.mapper.ShopMapper;
import com.example.wxminiprogram.pojo.Seller;
import com.example.wxminiprogram.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SellerServiceImpl implements SellerService {
    @Autowired
    SellerMapper sellerMapper;
    @Autowired
    ShopMapper shopMapper;
    @Override
    public Seller login(String account, String password){
        if(this.sellerMapper.countByAccountAndPassword(account,password) == 1){
            Integer id = this.sellerMapper.getIdByAccount(account);
            return this.sellerMapper.getById(id);
        }
        else{
            return null;
        }
    }
    @Override
    public Boolean register(String account, String password){
        if(this.sellerMapper.countByAccount(account)!=0){
            return false;
        }
        else{

            this.sellerMapper.insertByAccountAndPassword(account,password);
            this.shopMapper.insertBySellerId(this.sellerMapper.getIdByAccount(account));
            return true;
        }


    }
}
